import { dateFtt } from 'vue-xiaobu-utils'

/**
 * 获取展示友好的时间
 * @param {String} date // 传入的日期的毫秒数
 */
function getFriendlyTime(date) {
  // date = '2019-03-17 08:11:02'
  let createDate = new Date(date)
  let time = createDate.getTime()
  let today = new Date()
  let ms =
    1000 *
    (today.getHours() * 3600 + today.getMinutes() * 60 + today.getSeconds())
  // 今天的日期的毫秒数
  let msToday = today.getTime()
  let ret = ''
  if (msToday - time < ms) {
    ret = '今天 ' + dateFtt('hh:mm', date)
  } else if (msToday - time < ms + 24 * 3600 * 1000) {
    ret = '昨天 ' + dateFtt('hh:mm', date)
    // } else if (ms_today - time < (ms + 24 * 3600 * 1000 * 2)) {
    //   ret = '前天'
  } else if (createDate.getFullYear() === today.getFullYear()) {
    // ret = dateFtt('MM月dd日 hh:mm', date)
    ret = dateFtt('M月d日 hh:mm', date)
  } else {
    // ret = dateFtt('yyyy年MM月dd日 hh:mm', date)
    ret = dateFtt('yyyy年M月d日 hh:mm', date)
  }
  return ret
}

export { getFriendlyTime }
